/*
 * $Id: SimpleStack.java 9 2006-03-08 10:21:59Z wjx $
 */
package com.someok.utils;

import java.util.LinkedList;
import java.util.NoSuchElementException;

/**
 * Simple Stack (LIFO) class.
 *
 * <p><a href="SimpleStack.java.html"><i>View Source</i></a></p>
 *
 * @version $Revision: 9 $ $Date: 2006-03-08 18:21:59 +0800 (星期三, 08 三月 2006) $
 */
public class SimpleStack {

	private LinkedList list = new LinkedList();

	/**
	 * Stack push.
	 *
	 * @param o
	 */
	public void push(Object o) {
		list.addLast(o);
	}

	/**
	 * Stack pop.
	 *
	 * @return poped object from stack
	 */
	public Object pop() {
		Object result = null;
		try {
			result = list.removeLast();
		} catch (NoSuchElementException nsee) {
		}
		return result;
	}


	public Object[] popAll() {
		Object[] res = list.toArray();
		list.clear();
		return res;
	}

	/**
	 * Peek element from stack.
	 *
	 * @return peeked object
	 */
	public Object peek() {
		return list.getLast();
	}


	/**
	 * Is stack empty?
	 *
	 * @return true if stack is empty
	 */
	public boolean isEmpty() {
		return list.isEmpty();
	}

}
